package com.canoe.text.common;

import com.canoe.common.Constant;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * text指令的参数及参数值
 *
 * @author: btm
 * @time: 20:49 2020/9/22
 **/
public class TextParameterValue {

    /**正则表达式**/
    private String regex;
    /**待处理文件基础路径**/
    private String sourceFileBasePath;
    /**待处理文件列表**/
    private List<String> fileNameList;
    /**生成的文件存放路径**/
    private String targetFilePath;
    /**是否只提取每一行中第一次匹配到的数据，默认false：提起所有的数据**/
    private boolean firstOne = false;
    /**是否将提取到的内容都合并为一行，默认false：每条数据单独占据一行**/
    private boolean singleLine = false;
    /**数据前缀**/
    private String prefix = "";
    /**数据后缀**/
    private String suffix = "";
    /**目标文件名**/
    private static final String TARGET_FILE_NAME = "/target.txt";
    /**当前所处路径**/
    private static final String CURRENT_PATH = Constant.CURRENT_PATH;
    /**文件路径分割符**/
    private static final String SYSTEM_PATH_SEPARATOR = Constant.getSystemPathSeparator();


    public String getRegex() {
        return regex;
    }

    public void setRegex(String regex) {
        this.regex = regex;
    }

    public void setSourceFilePath(String sourceFilePath) {
        this.fileNameList = new ArrayList<>(3);
        if (sourceFilePath.contains(SYSTEM_PATH_SEPARATOR)) {
            int i = sourceFilePath.lastIndexOf(SYSTEM_PATH_SEPARATOR);
            this.sourceFileBasePath = sourceFilePath.substring(0,i);
            this.fileNameList.add(sourceFilePath.substring(i+1));
        } else {
            this.fileNameList.add(sourceFilePath);
        }
    }

    public String getSourceFileBasePath() {
        return StringUtils.isBlank(this.sourceFileBasePath) ? CURRENT_PATH : this.sourceFileBasePath;
    }

    public void setSourceFileBasePath(String sourceFileBasePath) {
        this.sourceFileBasePath = sourceFileBasePath;
    }

    public List<String> getFileNameList() {
        return fileNameList;
    }

    public void setFileNameList(String[] fileNameList) {
        this.fileNameList = Arrays.asList(fileNameList);
    }

    public String getTargetFilePath() {
        if (StringUtils.isBlank(targetFilePath)) {
            targetFilePath = CURRENT_PATH;
        }
        return targetFilePath + TARGET_FILE_NAME;
    }

    public void setTargetFilePath(String targetFilePath) {
        this.targetFilePath = targetFilePath;
    }

    public boolean isFirstOne() {
        return firstOne;
    }

    public void setFirstOne(boolean firstOne) {
        this.firstOne = firstOne;
    }

    public boolean isSingleLine() {
        return singleLine;
    }

    public void setSingleLine(boolean singleLine) {
        this.singleLine = singleLine;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }
}
